package com.anzia.stream;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;

/**
 *@ClassName com.anzia.stream.BufferedOutputStream_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/9 13:22
 *@Version 1.0
 **/
public class BufferedOutputStream_Demo {

    public static void main(String[] args) throws Exception {

        //创建字节输出流
        FileOutputStream fos = new FileOutputStream("static\\buffer.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        //写入文件
        for (int i = 0; i < 10; i++) {
            bos.write("hello world！\r\n".getBytes()); //写入8k缓冲区
            bos.flush(); //刷新到硬盘
        }

        //关闭（内部调用flush方法）
        bos.close();
        System.out.println("执行完毕！");

    }

}
